package com.salary.model;

import java.util.HashMap;
import java.util.Map;

/**
 * 工资资料信息模型类
 */
public class SalesInfo {
    private double amount; // 金额
    private double acceptanceCollection; // 收承兑总吨数
    private String overduePaymentDeduction; // 超期回款扣款
    private Map<String, Double> salespersonAcceptance; // 每个业务员对应的收承兑吨数
    
    // 新增字段
    private Map<String, Double> overduePaymentDeductions; // 每个业务员的超期回款扣款
    private Map<String, Double> accountStatementDeductions; // 每个业务员的未按时交回对账单扣款
    private Map<String, Double> marketingRewards; // 每个业务员的营销奖励
    private Map<String, Double> marketingPenalties; // 每个业务员的营销惩罚
    private Map<String, Double> refundableDeductions; // 每个业务员的申请补回罚款
    
    // 添加销售总量字段，不包含东莞诚昌的数量
    private double totalSalesQuantity; // 销售总量（吨数），不包含东莞诚昌
    
    public SalesInfo() {
        this.salespersonAcceptance = new HashMap<>();
        // 初始化新增字段
        this.overduePaymentDeductions = new HashMap<>();
        this.accountStatementDeductions = new HashMap<>();
        this.marketingRewards = new HashMap<>();
        this.marketingPenalties = new HashMap<>();
        this.refundableDeductions = new HashMap<>();
        this.totalSalesQuantity = 0.0;
    }
    
    public SalesInfo(double amount, double acceptanceCollection, String overduePaymentDeduction) {
        this.amount = amount;
        this.acceptanceCollection = acceptanceCollection;
        this.overduePaymentDeduction = overduePaymentDeduction;
        this.salespersonAcceptance = new HashMap<>();
        // 初始化新增字段
        this.overduePaymentDeductions = new HashMap<>();
        this.accountStatementDeductions = new HashMap<>();
        this.marketingRewards = new HashMap<>();
        this.marketingPenalties = new HashMap<>();
        this.refundableDeductions = new HashMap<>();
        this.totalSalesQuantity = 0.0;
    }
    
    public double getAmount() {
        return amount;
    }
    
    public void setAmount(double amount) {
        this.amount = amount;
    }
    
    public double getAcceptanceCollection() {
        return acceptanceCollection;
    }
    
    public void setAcceptanceCollection(double acceptanceCollection) {
        this.acceptanceCollection = acceptanceCollection;
    }
    
    public String getOverduePaymentDeduction() {
        return overduePaymentDeduction;
    }
    
    public void setOverduePaymentDeduction(String overduePaymentDeduction) {
        this.overduePaymentDeduction = overduePaymentDeduction;
    }
    
    /**
     * 获取业务员对应的收承兑吨数映射
     */
    public Map<String, Double> getSalespersonAcceptance() {
        return salespersonAcceptance;
    }
    
    /**
     * 添加业务员的收承兑吨数
     * @param salesperson 业务员名称
     * @param tonnage 吨数
     */
    public void addSalespersonAcceptance(String salesperson, double tonnage) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            // 去掉名称两侧的空白字符
            String cleanName = salesperson.trim();
            // 如果已有该业务员记录，则累加吨数
            salespersonAcceptance.put(cleanName, 
                    salespersonAcceptance.getOrDefault(cleanName, 0.0) + tonnage);
        }
    }
    
    /**
     * 计算指定业务员的收承兑扣款金额（每吨扣5元）
     * @param salesperson 业务员名称
     * @return 该业务员的扣款金额
     */
    public double calculateSalespersonDeduction(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        
        // 标准化业务员名称（去除空白字符）
        String cleanName = salesperson.trim();
        
        if (salespersonAcceptance.containsKey(cleanName)) {
            double tonnage = salespersonAcceptance.get(cleanName);
            double deduction = tonnage * 5.0;
            // 四舍五入到两位小数
            return Math.round(deduction * 100) / 100.0;
        }
        return 0.0;
    }
    
    /**
     * 计算总收承兑扣款金额（每吨扣5元）
     * @return 总扣款金额
     */
    public double calculateAcceptanceDeduction() {
        return acceptanceCollection * 5.0;
    }
    
    // 新增方法 - 获取超期回款扣款Map
    public Map<String, Double> getOverduePaymentDeductions() {
        return overduePaymentDeductions;
    }
    
    // 新增方法 - 设置业务员的超期回款扣款
    public void setOverduePaymentDeduction(String salesperson, double amount) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            String cleanName = salesperson.trim();
            overduePaymentDeductions.put(cleanName, amount);
        }
    }
    
    // 新增方法 - 获取业务员的超期回款扣款
    public double getOverduePaymentDeduction(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        String cleanName = salesperson.trim();
        return overduePaymentDeductions.getOrDefault(cleanName, 0.0);
    }
    
    // 新增方法 - 获取未按时交回对账单扣款Map
    public Map<String, Double> getAccountStatementDeductions() {
        return accountStatementDeductions;
    }
    
    // 新增方法 - 设置业务员的未按时交回对账单扣款
    public void setAccountStatementDeduction(String salesperson, double amount) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            String cleanName = salesperson.trim();
            accountStatementDeductions.put(cleanName, amount);
        }
    }
    
    // 新增方法 - 获取业务员的未按时交回对账单扣款
    public double getAccountStatementDeduction(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        String cleanName = salesperson.trim();
        return accountStatementDeductions.getOrDefault(cleanName, 0.0);
    }
    
    // 新增方法 - 获取营销奖励Map
    public Map<String, Double> getMarketingRewards() {
        return marketingRewards;
    }
    
    // 新增方法 - 设置业务员的营销奖励
    public void setMarketingReward(String salesperson, double amount) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            String cleanName = salesperson.trim();
            marketingRewards.put(cleanName, amount);
        }
    }
    
    // 新增方法 - 获取业务员的营销奖励
    public double getMarketingReward(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        String cleanName = salesperson.trim();
        return marketingRewards.getOrDefault(cleanName, 0.0);
    }
    
    // 新增方法 - 获取营销惩罚Map
    public Map<String, Double> getMarketingPenalties() {
        return marketingPenalties;
    }
    
    // 新增方法 - 设置业务员的营销惩罚
    public void setMarketingPenalty(String salesperson, double amount) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            String cleanName = salesperson.trim();
            marketingPenalties.put(cleanName, amount);
        }
    }
    
    // 新增方法 - 获取业务员的营销惩罚
    public double getMarketingPenalty(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        String cleanName = salesperson.trim();
        return marketingPenalties.getOrDefault(cleanName, 0.0);
    }
    
    // 新增方法 - 获取申请补回罚款Map
    public Map<String, Double> getRefundableDeductions() {
        return refundableDeductions;
    }
    
    // 新增方法 - 设置业务员的申请补回罚款
    public void setRefundableDeduction(String salesperson, double amount) {
        if (salesperson != null && !salesperson.trim().isEmpty()) {
            String cleanName = salesperson.trim();
            refundableDeductions.put(cleanName, amount);
        }
    }
    
    // 新增方法 - 获取业务员的申请补回罚款
    public double getRefundableDeduction(String salesperson) {
        if (salesperson == null || salesperson.trim().isEmpty()) {
            return 0.0;
        }
        String cleanName = salesperson.trim();
        return refundableDeductions.getOrDefault(cleanName, 0.0);
    }
    
    /**
     * 获取销售总量（吨数），不包含东莞诚昌
     * @return 销售总量
     */
    public double getTotalSalesQuantity() {
        return totalSalesQuantity;
    }
    
    /**
     * 设置销售总量（吨数），不包含东莞诚昌
     * @param totalSalesQuantity 销售总量
     */
    public void setTotalSalesQuantity(double totalSalesQuantity) {
        this.totalSalesQuantity = totalSalesQuantity;
    }
    
    /**
     * 增加销售总量
     * @param quantity 增加的销售量
     */
    public void addToTotalSalesQuantity(double quantity) {
        this.totalSalesQuantity += quantity;
    }
    
    @Override
    public String toString() {
        return "SalaryInfo{" +
                "amount=" + amount +
                ", acceptanceCollection=" + acceptanceCollection +
                ", overduePaymentDeduction='" + overduePaymentDeduction + '\'' +
                ", salespersonAcceptance=" + salespersonAcceptance +
                ", overduePaymentDeductions=" + overduePaymentDeductions +
                ", accountStatementDeductions=" + accountStatementDeductions +
                ", marketingRewards=" + marketingRewards +
                ", marketingPenalties=" + marketingPenalties +
                ", refundableDeductions=" + refundableDeductions +
                ", totalSalesQuantity=" + totalSalesQuantity +
                '}';
    }
} 